package com.itheima.a03udpdemo2;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class ReceiveMessageDemo {
    public static void main(String[] args) throws IOException {
        //创建datagramSocket对象,绑定端口号
        DatagramSocket ds = new DatagramSocket(10086);

        //创建包来接收数据
        byte[] bytes = new byte[1024];
        DatagramPacket dp = new DatagramPacket(bytes, bytes.length);

        while (true) {
            //接收数据
            ds.receive(dp);

            //解析数据
            System.out.println(dp.getAddress().getHostAddress()
                    +"的"+dp.getPort()+"端口发来了"+new String(dp.getData()));
        }
    }
}
